﻿<template>
    <div class="SHZY-common-layout">
        <div class="SHZY-common-layout-center">
            <el-row class="SHZY-common-search-box" :gutter="16">
                <el-form @submit.native.prevent="">
                    <el-col :span="6">
                        <el-form-item label="条码">
                            <el-input v-model="query.barcode" placeholder="条码" clearable @keyup.enter.native="search"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="做番号 ">
                            <el-input v-model="query.no" placeholder="做番号 " clearable @keyup.enter.native="search"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="产品型号">
                            <el-input v-model="query.model" placeholder="产品型号" clearable @keyup.enter.native="search" />
                        </el-form-item>
                    </el-col>
                    <template v-if="showAll">
                        <el-col :span="6">
                            <el-form-item label="图号">
                                <el-input v-model="query.drawingNo" placeholder="图号" clearable @keyup.enter.native="search" />
                            </el-form-item>
                        </el-col>
                    </template>
                    <el-col :span="6">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
                            <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
                            <el-button type="text" icon="el-icon-arrow-down" @click="showAll = true"
                                v-if="!showAll">展开</el-button>
                            <el-button type="text" icon="el-icon-arrow-up" @click="showAll = false"
                                v-else>收起</el-button>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <div class="SHZY-common-layout-main SHZY-flex-main">
                <div class="SHZY-common-head">
                    <div>

                        <el-button type="text" icon="el-icon-download" @click="exportData()">导出</el-button>

                    </div>
                    <div class="SHZY-common-head-right">
                        <el-tooltip effect="dark" content="刷新" placement="top">
                            <el-link icon="icon-ym icon-ym-Refresh SHZY-common-head-icon" :underline="false"
                                @click="reset()" />
                        </el-tooltip>
                    </div>
                </div>
                <SHZY-table v-loading="listLoading" :data="list" custom-column  >
                    <el-table-column label="条码" prop="barcode" align="left" width="300" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="做番号 " prop="no" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="打印日期" prop="printDate" align="left" width="150" :show-overflow-tooltip="true"
                        :formatter="shzy.tableDateFormat">
                    </el-table-column>
                    <el-table-column label="单位名称" prop="name" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="产品型号" prop="model" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="箱号" prop="boxNo" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="箱名" prop="boxName" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="图号" prop="drawingNo" align="left" width="200" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="部件名称" prop="componentName" align="left" width="150"
                        :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="规格" prop="specifications" align="left" width="150"
                        :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="单位" prop="unit" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="数量" prop="qty" align="left" width="100" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column label="备注" prop="remark" align="left" :show-overflow-tooltip="true">
                    </el-table-column>
                  
                    <el-table-column label="操作" fixed="right" width="100">
                        <template slot-scope="scope">
                            <el-button type="text" @click="afreshprint(scope.row.id)"
                                icon="el-icon-printer">重新打印</el-button>

                        </template>
                    </el-table-column>
                </SHZY-table>
                <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize"
                    @pagination="initData" />
            </div>
        </div>
        <SHZY-Form v-if="formVisible" ref="SHZYForm" @refresh="refresh" />
        <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
    </div>
</template>
<script>
import restAPI from '@/api/q1/business/pick';
import SHZYForm from './Form'
import ExportBox from './ExportBox'
export default {
    components: { SHZYForm, ExportBox },
    data() {
        return {
            showAll: false,
            query: {
                barcode: undefined,
                no: undefined,
                model: undefined,
                drawingNo: undefined,
            },
            list: [],
            listLoading: true,
            multipleSelection: [],
            total: 0,
            listQuery: {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            },
            formVisible: false,
            exportBoxVisible: false,
            columnList: [
                { prop: 'barcode', label: '条码' },
                { prop: 'no', label: '做番号 ' },
                { prop: 'name', label: '单位名称' },
                { prop: 'model', label: '产品型号' },
                { prop: 'boxNo', label: '箱号' },
                { prop: 'boxName', label: '箱名' },
                { prop: 'drawingNo', label: '图号' },
                { prop: 'componentName', label: '部件名称' },
                { prop: 'specifications', label: '规格' },
                { prop: 'unit', label: '单位' },
                { prop: 'qty', label: '数量' },
                { prop: 'remark', label: '备注' },
                { prop: 'printDate', label: '打印日期' },
            ],
        }
    },
    computed: {
        menuId() {
            return this.$route.meta.modelId || ''
        }
    },
    created() {
        this.initData()
    },
    methods: {
        initData() {
            this.listLoading = true;
            let _query = {
                ...this.listQuery,
                ...this.query,
                menuId: this.menuId,
            };
            let query = {}
            for (let key in _query) {
                if (Array.isArray(_query[key])) {
                    query[key] = _query[key].join()
                } else {
                    query[key] = _query[key]
                }
            }
            restAPI.GetListRecord(query).then(res => {
                this.list = res.data.list
                this.total = res.data.pagination.total
                this.listLoading = false
            });
        },


        //重新打印
        afreshprint(id) {
            let query = {

                formDataId:id,
                printConfigId : "564705291665845573"
            }
            
           

            this.$confirm('确定重新打印吗?', '提示', {
                type: 'warning'
            }).then(() => {
                restAPI.fastreportUpdatePrint(query).then(res => {
                    const blob = new Blob([res], { type: 'application/pdf' })
                    const url = window.URL.createObjectURL(blob)
                    window.open(`${url}#filename=Zy`, "_blank")
                })
            }).catch(() => {
            });

        },
        //导出
        exportData() {
            this.exportBoxVisible = true
            this.$nextTick(() => {
                this.$refs.ExportBox.init(this.columnList)
            })
        },
        download(data) {
            let query = { ...data, ...this.listQuery, ...this.query, menuId: this.menuId }

            restAPI.Export(query).then(res => {

                if (!res.data.url) return
                this.shzy.downloadFile(res.data.url)
                this.$refs.ExportBox.visible = false
                this.exportBoxVisible = false

            })
        },
        search() {
            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            }
            this.initData()
        },
        refresh(isrRefresh) {
            this.formVisible = false
            if (isrRefresh) this.reset()
        },
        reset() {
            for (let key in this.query) {
                this.query[key] = undefined
            }
            this.listQuery = {
                currentPage: 1,
                pageSize: 20,
                sort: "desc",
                sidx: "",
            }
            this.initData()
        }
    }
}
</script>